package com.carkeeper.appraise.service.impl;

import com.alibaba.fastjson.JSON;
import com.carkeeper.appraise.config.RabbitMQConfig;
import com.carkeeper.appraise.dao.AppraisalMapper;
import com.carkeeper.appraise.pojo.Appraisal;
import com.carkeeper.appraise.service.AppraisalService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AppraisalServiceImpl implements AppraisalService {

    @Autowired
    private AppraisalMapper appraisalMapper;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Transactional
    @Override
    public List<Appraisal> findAll() {
        Appraisal appraisal = new Appraisal();
        appraisal.setIsDelete(0);
        List<Appraisal> list = appraisalMapper.select(appraisal);
        return list;
    }

    @Override
    public void del(String orderId) {
        Appraisal appraisal = new Appraisal();
        appraisal.setOrderId(orderId);
        appraisal.setIsDelete(1);
        int update = appraisalMapper.update(appraisal);
        System.out.println(update);

    }

    @Override
    public int add(Appraisal appraisal) {
        int insert = appraisalMapper.insert(appraisal);
        rabbitTemplate.convertAndSend("", RabbitMQConfig.AD_APPRAISAL_QUEUE, JSON.toJSONString(appraisal));
        return insert;
    }
}
